<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="手机号" prop="phoneNum">
        <el-input v-model="queryParams.phoneNum" placeholder="请输入操作原因" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="爱洞ID" prop="platformId">
        <el-input v-model="queryParams.platformId" placeholder="请输入操作原因" clearable
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="封号类型" prop="limitType">
        <el-select v-model="queryParams.limitType" placeholder="请选择封号类型" clearable>
          <el-option v-for="dict in dict.type.limit_type" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="userBannedList">
      <el-table-column label="用户头像" align="center" prop="headUrl">
        <template slot-scope="scope">
          <ImagePreview :src="scope.row.headUrl" width="50px" height="50px">

          </ImagePreview>
        </template>

      </el-table-column>

      <el-table-column label="爱动ID" align="center" prop="platformId">
        <template slot-scope="scope">
          <a v-if="scope.row.sex === 1" style="color: #FF6EC7" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
          <a v-else style="color: #7099F9" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" align="center" prop="nickName"/>
      <el-table-column label="手机号" align="center" prop="phoneNum"/>

      <el-table-column label="封号类型" align="center" prop="limitType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.limit_type" :value="scope.row.limitType"/>
        </template>
      </el-table-column>

      <el-table-column label="开始时间" align="center" prop="createTime">
      </el-table-column>
      <el-table-column label="结束时间" align="center" prop="endTime">
      </el-table-column>
      <el-table-column label="操作原因" align="center" prop="reason"/>
      <el-table-column label="备注" align="center" prop="remark"/>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"/>


  </div>
</template>

<script>
import {
  listUserBanned
} from "@/api/service/userBanned/userBanned";

export default {
  name: "UserBanned",
  dicts: ['limit_type'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 封号信息表格数据
      userBannedList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        limitType: undefined,
        phoneNum: undefined,
        platformId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询封号信息列表 */
    getList() {
      this.loading = true;
      listUserBanned(this.queryParams).then(response => {
        this.userBannedList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateUserBanned(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addUserBanned(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },

    /**
     * 点击用户爱动id跳转到用户页面
     * @param platformId
     */
    toUserInfo(platformId) {
      this.$router.push({path: "/user/appUser", query: {id: platformId}});
    }

  }
};
</script>
